Skip to content

fix: clear latestCtx on executionContextDestroyed to prevent stale context routing#3

Open
void0x14 wants to merge 4 commits into
VulpineOS:mainfrom
void0x14:fix/latestctx-stale-context
Open

fix: clear latestCtx on executionContextDestroyed to prevent stale context routing#3
void0x14 wants to merge 4 commits into
VulpineOS:mainfrom
void0x14:fix/latestctx-stale-context

Conversation

@void0x14

@void0x14 void0x14 commented May 29, 2026

Copy link
Copy Markdown

Closes #1
…ntext routing

When a subframe's execution context is destroyed, latestCtx was not cleared. This caused Runtime.evaluate (without contextId) to keep routing to the destroyed context, producing persistent 'Failed to find execution context' errors that never recovered.

Fix:

  • executionContextDestroyed: clear latestCtx if it matches the destroyed context
  • executionContextsCleared: clear latestCtx for the session (navigation case)
  • Add test assertion verifying latestCtx is cleared after context destruction

void0x14 added 4 commits May 29, 2026 03:02
…ntext routing

When a subframe's execution context is destroyed, latestCtx was not cleared.
This caused Runtime.evaluate (without contextId) to keep routing to the
destroyed context, producing persistent 'Failed to find execution context'
errors that never recovered.

Fix:
- executionContextDestroyed: clear latestCtx if it matches the destroyed context
- executionContextsCleared: clear latestCtx for the session (navigation case)
- Add test assertion verifying latestCtx is cleared after context destruction
BinaryMessage (opcode 0x02) was always sent regardless of compression
state. CDP wire format is JSON text — engine recvWsTextAlloc only
handles TEXT (0x01) and CONTINUATION (0x00) frames, causing WsFrameError.

- Send: TextMessage when compress=false, BinaryMessage when compress=true
- SendBatch: same fix

SOURCE: Chrome DevTools Protocol — wire format is JSON text frames
SOURCE: RFC 6455 Section 5.2 — opcode 0x01 = text, 0x02 = binary
When a subframe's execution context is destroyed, latestCtx is cleared
(fix VulpineOS#1). But Juggler requires executionContextId in Runtime.evaluate.
Without a fallback, foxbridge sends undefined → Juggler rejects.

Add mainCtx map that tracks the main frame's execution context per
session. Unlike latestCtx, mainCtx is updated on every main frame
context creation (surviving navigation) and only cleared on
executionContextsCleared (full navigation reset).

Fallback chain: latestCtx → mainCtx → empty (Juggler error)
This ensures Runtime.evaluate always has a valid contextId.

Also fix binary framing: Send() now uses TextMessage (opcode 0x01)
for uncompressed CDP frames instead of always BinaryMessage (0x02).

Fixes VulpineOS#1
Instead of hardcoding type="undefined" when Juggler omits the type
field, infer the actual type from the JSON value:
- String value → type="string"
- Boolean value → type="boolean"
- Number value → type="number"

This fixes "Runtime.evaluate expected string, got type=undefined"
errors in CDP clients that check the type field.

SOURCE: Chrome DevTools Protocol — Runtime.evaluate returns {result:{type,value}}
@void0x14 void0x14 changed the title fix: clear latestCtx on executionContextDestroyed to prevent stale context routing fix: clear latestCtx on executionContextDestroyed to prevent stale co… May 29, 2026
@void0x14 void0x14 changed the title fix: clear latestCtx on executionContextDestroyed to prevent stale co… fix: clear latestCtx on executionContextDestroyed to prevent stale context routing May 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: latestCtx not cleared on Runtime.executionContextDestroyed — stale context causes persistent evaluate failures

1 participant